package com.lb.activity.sys.controller;

import com.lb.activity.po.DictionaryData;
import com.lb.activity.sys.service.DictionaryService;
import com.lb.activity.sys.service.PicManagementService;
import com.lb.activity.util.ResultUtil;
import com.lb.activity.vo.PicManagementVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * 图片管理
 * @author 001030
 */
@RestController
public class PicManagementController {

    @Autowired
    private DictionaryService dictionaryService;

    @Autowired
    private PicManagementService picManagementService;

    /**
     * 展示页面玩
     * @return
     */
    @GetMapping("/showPic")
    public ModelAndView showPic(){
        return new ModelAndView("pic/pic");
    }


    /**
     * to  添加页面
     * @return
     */
    @GetMapping("toAddPic")
    public ModelAndView toAddPic(){
        List<DictionaryData> picTypes = dictionaryService.dictionaryDatas("picType");
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("pic/pic-add");
        modelAndView.addObject("picTypes",picTypes);
        return modelAndView;
    }

    /**
     * 添加图片
     * @param picManagementVo
     * @return
     */
    @PostMapping("addPicManagement")
    public ResultUtil addPicManagement(PicManagementVo picManagementVo){
        ResultUtil resultUtil = picManagementService.addPicManagement(picManagementVo);
        return resultUtil;
    }

    /**
     * 页面集合
     * @param picManagementVo
     * @return
     */
    @GetMapping("pics")
    public ResultUtil pics(PicManagementVo picManagementVo){
        ResultUtil resultUtil = picManagementService.pics(picManagementVo);
        return resultUtil;
    }

    @PostMapping("removePic")
    public ResultUtil removePic(Long id){
        ResultUtil resultUtil = picManagementService.removePic(id);
        return resultUtil;
    }
}
